<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        new Promise((resolve, reject) => {
            console.log("开始请求A数据");
            try {
                // throw new Error("网络不稳定")
                // 异步请求代码
                setTimeout(() => {
                    // 发送请求,返回结果
                    console.log("A数据请求成功");
                    // 模拟请求成功的数据
                    const user = {
                        name: "张三"
                    }
                    resolve(user)
                }, 2000)
            } catch (e) {
                reject(e.message)
            }
        })

            .then(value => {
                return new Promise((resolve, reject) => {
                    console.log("开始请求B数据");
                    try {
                        throw new Error("网络不稳定")

                        setTimeout(() => {
                            console.log("B数据请求成功");
                            // 模拟获取成功的B数据
                            const sex = {
                                sex: "男"
                            }
                            resolve({
                                ...value,
                                ...sex
                            })
                        }, 2000)
                    } catch (e) {
                        reject(e.message)
                    }
                })
            })

            .then(value => {
                console.log("返回结果", value);
            })

            .catch(reason => {
                console.log("有问题");
            })


    </script>
</body>

</html>